package com.example.rfidserver.ticket.subactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.example.rfidserver.R;
import com.example.rfidserver.dao.TicketDao;
import com.example.rfidserver.pojo.Ticket;
import com.example.rfidserver.ticket.adapter.TicketSubAdapter;
import com.example.rfidserver.utils.DialogHelper;

import java.util.List;

public class TicketDeleteActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ticket_delete);
        TicketDao ticketDao = new TicketDao();
        List<Ticket> ticketInfo = ticketDao.getTicketInfo();
        initview(this,ticketInfo);
    }


    @Override
    protected void onResume() {
        super.onResume();
        TicketDao ticketDao = new TicketDao();
        List<Ticket> ticketInfo = ticketDao.getTicketInfo();
        initview(this,ticketInfo);
    }

    public void initview(Context context, List<Ticket> tickets) {
        final ListView mylistview = findViewById(R.id.mylistview_ticket_delete);
        final TicketSubAdapter ticketSubAdapter = new TicketSubAdapter(context, tickets);
        System.out.println(tickets);
        mylistview.setAdapter(ticketSubAdapter);
        //设置Item项的点击事件
        mylistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //得到点击的该用户的所有信息
                Ticket item_ticket = ticketSubAdapter.getItem(position);
                System.out.println(item_ticket);
                //显示对话框，提示是否要删除
                int ticket_id = item_ticket.getTicket_id();
                DialogHelper.commonDialog(TicketDeleteActivity.this,"对话框","你要删除门票:"+ticket_id+"吗?",item_ticket);
            }
        });
    }

}
